package com.puppy.mapper;

import com.puppy.pojo.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeptMapper {

//    手动结果映射
//    @Results({
//        @Result(column = "create_time", property = "createTime"),
//        @Result(column = "update_time", property = "updateTime")
//    })
//    起别名
//    @Select("select id,name,create_time createTime,update_time updateTime from depts order by update_time desc")
    @Select("select id,name,create_time,update_time from depts order by update_time desc")
    List<Dept> findAll();

    @Delete("delete from depts where id=#{id}")
    void deleteById(Integer id);

    @Insert("insert into depts(name,create_time,update_time) values(#{name},#{createTime},#{updateTime})")
    void addByName(Dept dept);

    @Select("select id,name,create_time,update_time from depts where id=#{id}")
    Dept getByID(Integer id);

    @Update("update depts set name=#{name},update_time=#{updateTime} where id=#{id}")
    void updateById(Dept dept);
}
